package com.itita.player.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itita.player.R;
import com.itita.player.pojo.MainBookCityClassfy;

public class BookCityListAdatper extends BaseAdapter {
	private List<MainBookCityClassfy> bookcitys;
	private Context context;
	
	public BookCityListAdatper(List bookcitys, Context context) {
		this.bookcitys = bookcitys;
		this.context = context;
	}
	
	@Override
	public int getCount() {
		return bookcitys.size();
	}

	@Override
	public Object getItem(int position) {
		return bookcitys.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(null == convertView) {
			convertView = View.inflate(context, R.layout.bookcity_booklist, null);
			holder = new ViewHolder();
			holder.layout = (RelativeLayout) convertView.findViewById(R.id.bookcity_RelativeLayout);
			holder.textView = (TextView) convertView.findViewById(R.id.bookcity_booklist_TextView);
			holder.imageView = (ImageView) convertView.findViewById(R.id.bookcity_booklist_nexticon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder)convertView.getTag();
		}
		
		if(position % 2 == 0) {
			holder.layout.setBackgroundResource(R.drawable.bg_boollist_unselected);	
		} else {
			holder.layout.setBackgroundResource(R.drawable.bookcity_booklist_black);
		}
		holder.textView.setText(bookcitys.get(position).getName());
		holder.imageView.setBackgroundResource(R.drawable.bookcity_nexticon_black);
		return convertView;
	}
	
	static class ViewHolder {
		RelativeLayout layout;
		TextView textView;
		ImageView imageView;
	}
}
